package com.ruoyi.web.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.UserLoginToken;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.ResultCodeEnum;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.BaseAndGroup;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.UserBaseGroup;
import com.ruoyi.system.service.IDataLoadService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/web/dataLoad")
public class DataLoadController extends BaseController {

    @Autowired
    private IDataLoadService dataLoadService;

    /**
     * 用户进入,加载 大屏分组和大屏
     */
//    @UserLoginToken
    @PostMapping("/showBaseData")
    public R showBaseData(@Validated BaseAndGroup baseAndGroup)
    {
        // 取身份信息【前台用的是JWT验证用户的，暂时不清楚怎么获取用户ID】
        baseAndGroup.setUserId(1);
        List<Object> list = dataLoadService.showBaseData(baseAndGroup);//测试默认用户ID为1
        return R.setResult(ResultCodeEnum.SUCCESS).data("data",list);
    }

    /**
     * 添加大屏分组
     * @return
     */
    @PostMapping("/addBaseGroup")
    public AjaxResult addBaseGroup(UserBaseGroup userBaseGroup){

        // 取身份信息【前台用的是JWT验证用户的，暂时不清楚怎么获取用户ID】
        int userId = 1;//暂时默认为1
        userBaseGroup.setCreateId(1+"");
        userBaseGroup.setCreateName("admin");
        userBaseGroup.setUserId(1);

        int i = dataLoadService.addBaseGroup(userBaseGroup);
        if(i>0){
            //成功后的操作
            return AjaxResult.success("添加大屏分组成功");
        }else{
            return AjaxResult.error("添加大屏分组失败");
//            throw new BusinessException("添加大屏分组失败！");
        }


    }
























}
